<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>监考人员安排</title>
    <link href="../../static/css/bootstrap.min.css" rel="stylesheet" th:href="@{/static/css/bootstrap.min.css}">
    <link href="../../static/css/dashboard.css" rel="stylesheet" th:href="@{/static/css/dashboard.css}">
</head>
<body>
<div th:insert="admin/common::topbar"></div>
<div class="container-fluid">
    <div class="row">
        <!--侧边栏-->
        <div th:insert="~{admin/common::sidebar(active='courseArrange.html')}">
        </div>
        <!--"-->
        <main class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4" role="main">
            <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
                <h3>安排课程</h3>
                <div class="btn-toolbar mb-2 mb-md-0">
                    <div class="btn-group mr-2">

                        <button class="btn btn-sm btn-outline-secondary" id="btn-quit-arrange-examTime">退出编辑</button>

                    </div>
                    <div class="btn-group mr-2">
                        <button class="btn btn-primary btn-sm btn-outline-secondary" id="btn-admin">管理员</button>
                        <button class="btn btn-sm btn-outline-secondary" id="btn-student">学生端</button>
                    </div>
                </div>
            </div>
            <form class="container-fluid col-md-5 col-md-pull-3" id="myForm" method="post" onsubmit="return check()"
                  th:action="@{/admin/arrangeTeacher}">
                <p style="color: red" th:if="${not #strings.isEmpty(error)}" th:text="${error}"></p>
                <p hidden id="error" style="color: red"></p>
                <div class="form-group form-inline" hidden>
                    <label class="form-check-inline" for="id">考场编号:</label>
                    <input class="form-control" id="id" name="id" readonly th:value="${exam.getId()}" type="text">
                </div>
                <div class="form-group form-inline">
                    <label class="form-check-inline" for="exam_place">考场地点:</label>
                    <input class="form-control" id="exam_place" name="exam_place" readonly
                           th:value="${exam.getExam_place()}" type="text">
                </div>
                <div class="form-group form-inline" hidden>
                    <label class="form-check-inline" for="exam_id">考试编号:</label>
                    <input class="form-control" id="exam_id" name="exam_id" readonly th:value="${exam.getExam_id()}"
                           type="text">
                </div>
                <div class="form-group form-inline">
                    <label class="form-check-inline" for="exam_name">考试名称:</label>
                    <input class="form-control" id="exam_name" name="exam_name" readonly
                           th:value="${exam.getExam_name()}" type="text">
                </div>
                <div class="form-group form-inline" hidden>
                    <label class="form-check-inline" for="exam_cid">考试科目编号:</label>
                    <input class="form-control" id="exam_cid" name="exam_cid" readonly th:value="${exam.getExam_cid()}"
                           type="text">
                </div>
                <div class="form-group form-inline">
                    <label class="form-check-inline" for="exam_cname">考试科目:</label>
                    <input class="form-control" id="exam_cname" name="exam_cname" readonly
                           th:value="${exam.getExam_cname()}" type="text">
                </div>
                <div class="form-group form-inline">
                    <label class="form-check-inline" for="tid_first">第一监考老师:</label>
                    <select class="form-control" id="tid_first" name="tid_first">
                        <option th:each="teacher:${teacherList}" th:text="${teacher.getTname()}"
                                th:value="${teacher.getTid()}"></option>
                    </select>
                </div>
                <div class="form-group form-inline">
                    <label class="form-check-inline" for="tid_second">第二监考老师:</label>
                    <select class="form-control" id="tid_second" name="tid_second">
                        <option th:each="teacher:${teacherList}" th:text="${teacher.getTname()}"
                                th:value="${teacher.getTid()}"></option>
                    </select>
                    <!--<input class="form-control" name="exam_time" id="exam_time" type="text">-->
                </div>
                <div class="form-group form-inline">
                    <button class="btn btn-primary " id="button" type="submit">添加</button>
                </div>
            </form>
        </main>
    </div>
</div>
<script src="../../static/js/jquery-3.6.0.min.js" th:src="@{/static/js/jquery-3.6.0.min.js}"
        type="text/javascript"></script>
<script src="../../static/js/bootstrap.min.js" th:src="@{/static/js/bootstrap.min.js}" type="text/javascript"></script>
<script src="../../static/js/btn.js" th:src="@{/static/js/btn.js}"></script>
<script>
    $(function () {
        $('#btn-quit-arrange-examTime').click(function () {
            let exam_id = [[${exam.getExam_id()}]];
            $(location).attr('href', '/admin/getExamSubjectList/' + exam_id);
        })

        function check() {
            let tid_first = $('#tid_first').val();
            let tid_second = $('#tid_second').val();
            let exam_id = $('#exam_id').val();
            let exam_cid = $('#exam_cid').val();
            let error = $('#error');
            $.get({
                url: "/admin/ajax/judgeExamTeacher",
                data: {"tid_first": tid_first, "tid_second": tid_second, "exam_id": exam_id, "exam_cid": exam_cid},
                success: function (result) {
                    if (result === true) {
                        return true;
                    } else {
                        error.text("监考老师出现冲突!");
                        error.show();
                        return false;
                    }
                }
            })
        }
    })

</script>
</body>
</html>